var Adv_skd=require("./Adv_skd")

var e = require;
var t = module;
var o = exports;
var n,
    i = o,
    a =
        ((n = function (e, t) {
            return (n =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (e, t) {
                        e.__proto__ = t;
                    }) ||
                function (e, t) {
                    for (var o in t) t.hasOwnProperty(o) && (e[o] = t[o]);
                })(e, t);
        }),
        function (e, t) {
            function o() {
                this.constructor = e;
            }
            n(e, t), (e.prototype = null === t ? Object.create(t) : ((o.prototype = t.prototype), new o()));
        }),
    r = function (e, t, o, n) {
        var i,
            a = arguments.length,
            r = a < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, o)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(e, t, o, n);
        else
            for (var s = e.length - 1; s >= 0; s--)
                (i = e[s]) && (r = (a < 3 ? i(r) : a > 3 ? i(t, o, r) : i(t, o)) || r);
        return a > 3 && r && Object.defineProperty(t, o, r), r;
    };
Object.defineProperty(i, "__esModule", {value: !0});
var s = e("AssetsMap"),
    c = e("BundleNames"),
    l = e("GlobalParam"),
    d = e("Util"),
    u = e("ConfigGameData"),
    p = e("GameData"),
    h = e("GameOverData"),
    f = e("PlayerLevel"),
    _ = e("LoginProxy"),
    y = e("RankProxy2"),
    m = e("SkinLevelData"),
    g = cc._decorator,
    v = g.ccclass,
    w = g.property,
    b = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.node_label_user_name = null),
                (t.node_sprite_user_icon = null),
                (t.btn_next = null),
                (t.isOppoView = !1),
                t
            );
        }
        return (
            a(t, e),
            (t.prototype.onLoad = function () {
                this.isCache = !1;
            }),
            (t.prototype.onEnable = function () {
                Adv_skd.default.instance.hideAllAdv();
                Adv_skd.default.instance.showGridAdRight();
                Adv_skd.default.instance.showGridAdLeft();
                Adv_skd.default.instance.showInterstitialAd();
            }),
            (t.prototype.onDisable = function () {
                ad.curr_platform == window.ad.Platform.OPPO && ad.adInterface.hideNativePatch(!1),
                    ad.curr_platform == window.ad.Platform.BAI_DU && ad.adInterface.hideBanner(!1);
            }),
            (t.prototype.start = function () {
                ad.curr_platform == window.ad.Platform.QQ && ad.adInterface.showBanner(),
                    ad.curr_platform == window.ad.Platform.WECHAT && ad.adInterface.showBanner(),
                    ad.curr_platform == window.ad.Platform.TOU_TIAO && ad.adInterface.showBanner(),
                    ad.curr_platform == window.ad.Platform.OPPO
                        ? (ad.adInterface.hideNativeBanner(!1),
                          ad.adInterface.isNativePatchReady() && ad.adInterface.showNativePatch("NativePatch_2"))
                        : ad.curr_platform == window.ad.Platform.MEI_ZU
                        ? ad.adInterface.showInterstitial()
                        : ad.curr_platform == window.ad.Platform.HUAWEI_GAME
                        ? ad.adInterface.showNativeInterstitial()
                        : ad.curr_platform == window.ad.Platform.BAI_DU
                        ? ad.adInterface.showBanner()
                        : ad.curr_platform == window.ad.Platform.VIVO &&
                          (ad.adInterface.isNativeInterstitialAdReady()
                              ? ad.adInterface.showNativeInterstitial()
                              : ad.adInterface.showInterstitial()),
                    ad.curr_platform == window.ad.Platform.VIVO &&
                        (ad.adInterface.hideNativeBanner(!1), ad.adInterface.hideBanner(!1));
                for (
                    var e = this.node.getChildByName("content"),
                        t = e.getChildByName("PlayerData"),
                        o =
                            (e.getChildByName("GameData").getChildByName("itemsParent"),
                            e.getChildByName("UserData").getChildByName("scores")),
                        n = h.default.instance.cloneDataList(),
                        i = null,
                        a = 0;
                    a < n.length;
                    a++
                ) {
                    var r = n[a];
                    0 == a ? (i = r) : r.score > i.score && (i = r);
                }
                (i.level_addScore += 1), this.setItem(1, i);
                var s = null;
                for (a = 0; a < n.length; a++)
                    (r = n[a]), 0 == a ? (s = r) : r.score + r.oldScore > s.score + s.oldScore && (s = r);
                (s.level_addScore += 1), this.setItem(2, s);
                var c = null;
                for (a = 0; a < n.length; a++)
                    (r = n[a]),
                        0 == a
                            ? (c = r)
                            : (r.killNum > c.killNum && (c = r),
                              r.killNum == c.killNum && r.killScore > c.killScore && (c = r));
                (c.level_addScore += 1), this.setItem(3, c);
                var l = null;
                for (a = 0; a < n.length; a++) (r = n[a]), 0 == a ? (l = r) : r.killScore > l.killScore && (l = r);
                (l.level_addScore += 1), this.setItem(4, l);
                var u = null;
                for (a = 0; a < n.length; a++)
                    (r = n[a]), 0 == a ? (u = r) : r.level_addScore > u.level_addScore && (u = r);
                for (a = 1; a < 5; a++)
                    o.getChildByName("star" + a).getChildByName("star").active = a < u.level_addScore;
                for (this.refreshUserInfo(u), this.refreshPlayerLevel(u), a = 0; a < n.length; a++)
                    if ((r = n[a]).snake_name == u.snake_name) {
                        (t.getChildByName("label_item1").getComponent(cc.Label).string = r.score + ""),
                            (t.getChildByName("label_item2").getComponent(cc.Label).string = r.score + r.oldScore + ""),
                            (t.getChildByName("label_item3").getComponent(cc.Label).string = r.killNum + ""),
                            (t.getChildByName("label_item4").getComponent(cc.Label).string = r.killScore + "");
                        break;
                    }
                for (a = 0; a < n.length; a++)
                    if (n[a].snake_name == p.default.instance.UserName) {
                        var f = n[a].oldScore + n[a].score,
                            _ = d.default.getItem("TimeLimitHistory", "0");
                        if ((console.log(f, Number(_)), f >= Number(_))) {
                            d.default.setItem("TimeLimitHistory", f + "");
                            var m = game.appFacade.retrieveProxy(y.default.NAME);
                            console.log("reportRankData"), m.reportRankData(Number(f));
                        }
                    }
            }),
            (t.prototype.refreshPlayerLevel = function (e) {
                var t = this.node.getChildByName("content").getChildByName("UserData"),
                    o = t.getChildByName("gameLevel"),
                    n = t.getChildByName("stars");
                if (e.snake_name == p.default.instance.UserName) {
                    for (var i = f.default.instance.getPlayerLevel(), a = 1; a < 4; a++)
                        n.getChildByName("star" + a).getChildByName("star").active = a <= i.star;
                    var r = game.BundleManager.instance
                        .getBundle(c.default.Start)
                        .get(s.default.StartBundle.textures.assetsList[i.type], cc.SpriteFrame);
                    o.getComponent(cc.Sprite).spriteFrame = r;
                } else {
                    var u = Number(d.default.getItem("AIRandLevelScore" + e.snake_name, "1"));
                    d.default.setItem("AIRandLevelScore" + e.snake_name, u + e.level_addScore);
                    var h = l.default.PlayerLevelData,
                        _ = void 0;
                    for (a = 0; a < h.length; a++) {
                        var y = h[a];
                        u >= y.start_score && u <= y.end_score && (_ = y);
                    }
                    for (_ || (_ = h[h.length - 1]), a = 1; a < 4; a++)
                        n.getChildByName("star" + a).getChildByName("star").active = a <= _.star;
                    (r = game.BundleManager.instance
                        .getBundle(c.default.Start)
                        .get(s.default.StartBundle.textures.assetsList[_.type], cc.SpriteFrame)),
                        (o.getComponent(cc.Sprite).spriteFrame = r);
                }
            }),
            (t.prototype.refreshUserInfo = function (e) {
                var t = this;
                if (e.snake_name == p.default.instance.UserName)
                    game.appFacade.retrieveProxy(_.default.NAME).loginVO.userInfo,
                        cc.assetManager.loadBundle("popup", function (e, o) {
                            if (!e) {
                                var n = p.default.instance.getUserSkin(),
                                    i = m.SkinLevelData.instance.skinList[n];
                                o.load("textures/EggView/skin_icon/" + i.name, cc.SpriteFrame, function (e, o) {
                                    if (e)
                                        return (
                                            console.log("加载头像出错：", "textures/EggView/skin_icon/" + i.name),
                                            void cc.error(e.message || e)
                                        );
                                    t.node_sprite_user_icon.getComponent(cc.Sprite).spriteFrame = o;
                                });
                            }
                        });
                else {
                    this.node_label_user_name.getComponent(cc.Label).string = e.snake_name;
                    var o = u.default.instance.getIconByAIName(e.snake_name);
                    cc.assetManager.loadBundle("popup", function (e, n) {
                        e ||
                            n.load(o, cc.SpriteFrame, function (e, i) {
                                if (e)
                                    return (
                                        console.log("排位结束加载头像出错：", o),
                                        void n.load(
                                            "textures/EggView/skin_icon/kitty",
                                            cc.SpriteFrame,
                                            function (e, n) {
                                                if (e)
                                                    return (
                                                        console.log("排位结束加载头像出错：", o),
                                                        void cc.error(e.message || e)
                                                    );
                                                t.node_sprite_user_icon.getComponent(cc.Sprite).spriteFrame = n;
                                            }
                                        )
                                    );
                                t.node_sprite_user_icon.getComponent(cc.Sprite).spriteFrame = i;
                            });
                    });
                }
            }),
            (t.prototype.onClick_btn_next = function () {
                this.closeView(!1),
                    ad.curr_platform == window.ad.Platform.OPPO && ad.adInterface.isNativePatchReady()
                        ? game.PopupManager.instance.showPopView(s.default.PopupMap.GameOverView2_1, null, !1, !1)
                        : game.PopupManager.instance.showPopView(
                              s.default.PopupMap.GameOverView2,
                              {ttShare: !0},
                              !1,
                              !1
                          );
            }),
            (t.prototype.addEvent = function () {
                this.btn_next.node.on(game.EngineEventType.NodeEvent.click, this.onClick_btn_next, this);
            }),
            (t.prototype.removeEvent = function () {
                this.btn_next.node.off(game.EngineEventType.NodeEvent.click, this.onClick_btn_next, this);
            }),
            (t.prototype.setItem = function (e, t) {
                var o = this.node
                    .getChildByName("content")
                    .getChildByName("GameData")
                    .getChildByName("itemsParent")
                    .getChildByName("item" + e);
                if (
                    (1 == e
                        ? (o.getChildByName("label_data").getComponent(cc.Label).string = t.score + "")
                        : 2 == e
                        ? (o.getChildByName("label_data").getComponent(cc.Label).string = t.score + t.oldScore + "")
                        : 3 == e
                        ? (o.getChildByName("label_data").getComponent(cc.Label).string = t.killNum + "")
                        : 4 == e && (o.getChildByName("label_data").getComponent(cc.Label).string = t.killScore + ""),
                    (o.getChildByName("label_name").getComponent(cc.Label).string = t.snake_name + ""),
                    t.snake_name == p.default.instance.UserName)
                )
                    game.appFacade.retrieveProxy(_.default.NAME).loginVO.userInfo,
                        cc.assetManager.loadBundle("popup", function (e, t) {
                            if (!e) {
                                var n = p.default.instance.getUserSkin(),
                                    i = m.SkinLevelData.instance.skinList[n];
                                t.load("textures/EggView/skin_icon/" + i.name, cc.SpriteFrame, function (e, t) {
                                    if (e)
                                        return (
                                            console.log("加载头像出错：", "textures/EggView/skin_icon/" + i.name),
                                            void cc.error(e.message || e)
                                        );
                                    o
                                        .getChildByName("UserProfile")
                                        .getChildByName("mask")
                                        .getChildByName("user_icon")
                                        .getComponent(cc.Sprite).spriteFrame = t;
                                });
                            }
                        });
                else {
                    var n = u.default.instance.getIconByAIName(t.snake_name);
                    cc.assetManager.loadBundle("popup", function (e, t) {
                        e ||
                            t.load(n, cc.SpriteFrame, function (e, i) {
                                if (e)
                                    return (
                                        console.log("排位结束加载头像出错：", n),
                                        void t.load(
                                            "textures/EggView/skin_icon/kitty",
                                            cc.SpriteFrame,
                                            function (e, t) {
                                                if (e)
                                                    return (
                                                        console.log("排位结束加载头像出错：", n),
                                                        void cc.error(e.message || e)
                                                    );
                                                o
                                                    .getChildByName("UserProfile")
                                                    .getChildByName("mask")
                                                    .getChildByName("user_icon")
                                                    .getComponent(cc.Sprite).spriteFrame = t;
                                            }
                                        )
                                    );
                                o
                                    .getChildByName("UserProfile")
                                    .getChildByName("mask")
                                    .getChildByName("user_icon")
                                    .getComponent(cc.Sprite).spriteFrame = i;
                            });
                    });
                }
                var i = game.BundleManager.instance
                    .getBundle(c.default.Start)
                    .get(s.default.StartBundle.textures.assetsList[t.randLevel], cc.SpriteFrame);
                o.getChildByName("gameLevel1").getComponent(cc.Sprite).spriteFrame = i;
            }),
            r([w(cc.Node)], t.prototype, "node_label_user_name", void 0),
            r([w(cc.Node)], t.prototype, "node_sprite_user_icon", void 0),
            r([w(cc.Button)], t.prototype, "btn_next", void 0),
            r([w(cc.Boolean)], t.prototype, "isOppoView", void 0),
            r([v], t)
        );
    })(game.BasePopView);
i.default = b;
